home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / libraries / string-ext / parse-string.dylan < prev    next >
Encoding:
Text File  |  1995-03-15  |  2.2 KB  |  69 lines  |  [TEXT/ttxt]

  1. module:   parse-string
  2. author:   Nick Kramer (nkramer@cs.cmu.edu)
  3. synopsis: A useful little data structure that's not useful enough to 
  4.           export outside the library.
  5. copyright:  Copyright (C) 1994, Carnegie Mellon University.
  6.             All rights reserved.
  7. rcs-header: $Header: parse-string.dylan,v 1.1 94/11/08 22:57:16 nkramer Exp $
  8.  
  9. //======================================================================
  10. //
  11. // Copyright (c) 1994  Carnegie Mellon University
  12. // All rights reserved.
  13. // 
  14. // Use and copying of this software and preparation of derivative
  15. // works based on this software are permitted, including commercial
  16. // use, provided that the following conditions are observed:
  17. // 
  18. // 1. This copyright notice must be retained in full on any copies
  19. //    and on appropriate parts of any derivative works.
  20. // 2. Documentation (paper or online) accompanying any system that
  21. //    incorporates this software, or any part of it, must acknowledge
  22. //    the contribution of the Gwydion Project at Carnegie Mellon
  23. //    University.
  24. // 
  25. // This software is made available "as is".  Neither the authors nor
  26. // Carnegie Mellon University make any warranty about the software,
  27. // its performance, or its conformity to any specification.
  28. // 
  29. // Bug reports, questions, comments, and suggestions should be sent by
  30. // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  31. //
  32. //======================================================================
  33.  
  34.  
  35. // Parse strings: A string along with some state. A parse-string
  36. // supports two operations: lookahead and consume. lookahead(s) gets
  37. // the next character in the parse string, while consume(s) moves the
  38. // pointer along.
  39. //
  40. define class <parse-string> (<object>)
  41.   slot string :: <sequence>, required-init-keyword: string: ;
  42.   slot index :: <integer>, init-value: 0;
  43. end class <parse-string>;
  44.  
  45.  
  46. define method consume(s :: <parse-string>)
  47.   if (s.index >= size(s.string))
  48.     #f;
  49.   else
  50.     s.index := s.index + 1;
  51.     s;
  52.   end if;
  53. end method consume;
  54.  
  55.  
  56. define method lookahead(s :: <parse-string>)
  57.   if (s.index >= size(s.string))
  58.     #f;
  59.   else
  60.     s.string[s.index];
  61.   end if;
  62. end method lookahead;
  63.  
  64.  
  65. define method parse-string-done? (s :: <parse-string>)
  66.   s.index >= size(s.string);
  67. end method parse-string-done?;
  68.  
  69.